package cn.javase.base.internet._02_TCP通讯._单向通讯;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws IOException {
        try (
            Socket socket = new Socket("127.0.0.1", 9999);
            Scanner in = new Scanner(System.in)
        ) {
            while (true) {
                System.out.print("请输入：");
                String msg = in.next();
                BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
                bw.write(msg);
                bw.write(System.lineSeparator());
                bw.flush();
                if ("bye".equals(msg)) {
                    break;
                }
            }
        }
    }
}
